package cn.kgc.controller;


import cn.kgc.dto.ClassifyDto;
import cn.kgc.dto.Result;
import cn.kgc.pojo.Classify;
import cn.kgc.service.ClassifyService;
import cn.kgc.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品分类 前端控制器
 * </p>
 *
 * @author psq
 * @since 2021-08-05
 */
@RestController
@RequestMapping("/api/home")
public class ClassifyController {
    @Autowired//可写可不写
    private final ClassifyService classifyService;

    public ClassifyController(ClassifyService classifyService) {
        this.classifyService = classifyService;
    }

    @GetMapping("all")
    public List<Classify> findAll() {
        java.util.List<Classify> list = classifyService.list();
        return list;
    }

    @GetMapping("classifyTree")
    public Result<List<ClassifyDto>> findClassifyTree() {
        System.out.println("访问了findClassifyTree");
        List<ClassifyDto> list = classifyService.findClassifyTree();
        return ResultUtils.returnDataSuccess(list);
    }
}

